//
//  XMChatBaseTableViewCell.m
//  XMenSwift
//
//  Created by Jason on 2022/9/15.
//

#import "XMChatBaseTableViewCell.h"
#import "WZChatMacro.h"
#import "UIView+WZMChat.h"
#import "WZMChatHelper.h"


@interface XMChatBaseTableViewCell()

@end

@implementation XMChatBaseTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _userImageView = [[UIImageView alloc] init];
        _userImageView.layer.masksToBounds = YES;
        _userImageView.layer.cornerRadius = 25;
        
        _nickLabel = [[UILabel alloc] init];
        _nickLabel.textColor = [UIColor grayColor];
        _nickLabel.textAlignment = NSTextAlignmentLeft;
        _nickLabel.font = [UIFont systemFontOfSize:13];
        
        _bubbleImageView = [[UIImageView alloc] init];
        
        _activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        
        _retryBtn = [WZMChatBtn chatButtonWithType:WZMChatButtonTypeRetry];
        [_retryBtn setImage:[WZMInputHelper otherImageNamed:@"wzm_chat_retry"] forState:UIControlStateNormal];
        [_retryBtn addTarget:self action:@selector(retryBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)setConfig:(WZMChatMessageModel *)model {
    _model = model;
    _nickLabel.text = model.name;
    if (model.isSender) {
        _userImageView.image = [UIImage imageNamed:@"1_t"];
        _nickLabel.textAlignment = NSTextAlignmentRight;
        _bubbleImageView.image = [WZMChatHelper senderBubble];
        if (model.sendType == WZMMessageSendTypeWaiting) {
            _activityView.hidden = NO;
            [_activityView startAnimating];
            _retryBtn.hidden = YES;
        } else if (model.sendType == WZMMessageSendTypeSuccess) {
            _activityView.hidden = YES;
            [_activityView stopAnimating];
            _retryBtn.hidden = YES;
        } else {
            _activityView.hidden = YES;
            [_activityView stopAnimating];
            _retryBtn.hidden = NO;
        }
      
    } else {
        _userImageView.image = [UIImage imageNamed:@"2_t"];
        _nickLabel.textAlignment = NSTextAlignmentLeft;
        _bubbleImageView.image = [WZMChatHelper receiverBubble];
    }
}

- (void)retryBtnClick:(UIButton *)btn {
    NSLog(@"重新发送消息!");
}

@end
